products =  [["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]
shopcar = []

# 打印商品列表
def prtshoplist():
    print('-'*10,'商品列表','-'*10)
    for k,v in enumerate(products):
        print(k,v[0],v[1])

# 打印购物车
def prtshuocar():
    print('-' * 10, '已购买商品', '-' * 10)
    for k,v in enumerate(shopcar):
        print(k,v[0],v[1])

# 打印花费的总钱
def paymoney():
    totalmoney = 0
    totalcount = 0

    for k,v in enumerate(shopcar):
        totalmoney += v[1]
        totalcount += 1
    print('你一共买了{}件商品，总价是{}元。'.format(totalcount,totalmoney))
# 主功能
def shoping():
    prtshoplist()
    number = input("请输入你要购买的商品编号或者输入q退出:")
    while True:
        # if number not in [str(i) for i in range(6)]:
        #     # print("请输入正确的商品编号")
        #     continue
        # else:
        #     number = input("请输入你要购买的商品编号:")
        #     prtshoplist()
        #     number = input("请输入你要购买的商品编号:")
        if number == '0':
            shopcar.append(products[0])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == '1':
            shopcar.append(products[1])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == '2':
            shopcar.append(products[2])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == '3':
            shopcar.append(products[3])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == '4':
            shopcar.append(products[4])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == '5':
            shopcar.append(products[5])
            prtshoplist()
            number = input("请输入你要购买的商品编号或者输入q退出:")
        if number == 'q':
            prtshuocar()
            paymoney()
            break

shoping()

# 输入不存在的编号，有异常哦
